package gameadminlogic

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/common/utils"

	"navi-mumbai/app/rpc/game/internal/svc"
	"navi-mumbai/app/rpc/game/pb"
	"navi-mumbai/app/rpc/model/pg/game"
	"navi-mumbai/common/xerr"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateGameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateGameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateGameLogic {
	return &UpdateGameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 修改游戏
func (l *UpdateGameLogic) UpdateGame(in *pb.UpdateGameReq) (*pb.UpdateGameResp, error) {
	defer utils.RecoverPanic()

	var update game.UpdateGame
	_ = copier.Copy(&update, in)
	err := l.svcCtx.GameModel.UpdateGame(l.ctx, &update)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}

	return &pb.UpdateGameResp{}, nil
}
